package com.huanglj.taobaounion.ui.fragment;

import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.huanglj.taobaounion.R;
import com.huanglj.taobaounion.base.BaseFragment;
import com.huanglj.taobaounion.model.domain.OnSellResult;
import com.huanglj.taobaounion.presenter.IOnSellPagePresenter;
import com.huanglj.taobaounion.ui.adapter.OnSellAdapter;
import com.huanglj.taobaounion.utils.PresenterManager;
import com.huanglj.taobaounion.view.IOnSellCallBack;
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 */
public class RedPacketFragment extends BaseFragment implements IOnSellCallBack {

    @BindView(R.id.on_sell_refresh)
    TwinklingRefreshLayout mRefreshLayout;
    @BindView(R.id.on_sell_list_view)
    RecyclerView mRecyclerView;
    private IOnSellPagePresenter mOnSellPresenter;
    private OnSellAdapter mOnSellAdapter;

    @Override
    public int getRes() {
        return R.layout.fragment_ret_packet;
    }

    @Override
    protected void initView(View view) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        mOnSellAdapter = new OnSellAdapter();
        mRecyclerView.setAdapter(mOnSellAdapter);
    }

    @Override
    protected void initPresenter() {
        mOnSellPresenter = PresenterManager.getInstance().getOnSellPresenter();
        mOnSellPresenter.registerViewCallBack(this);
        mOnSellPresenter.getOnSellContent();
        mRefreshLayout.setOnRefreshListener(new RefreshListenerAdapter() {
        });
    }

    @Override
    public void onLoaded(OnSellResult result) {
        setUpState(State.SUCCESS);
        mOnSellAdapter.setData(result.getData().getTbk_dg_optimus_material_response().getResult_list().getMap_data());
    }

    @Override
    public void onMoreLoaded(OnSellResult result) {

    }

    @Override
    public void onMoreLoadedError() {

    }

    @Override
    public void onMoreLoadedEmpty() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mOnSellPresenter.unregisterViewCallBack(this);
    }

    @Override
    public void onLoading() {
        setUpState(State.LOADING);
    }

    @Override
    public void onEmpty() {

    }

    @Override
    public void onError(String errorMsg) {

    }
}